//
//  HamatonBottomView.swift
//  hamaton-app
//
//  Created by intyt on 2024/3/21.
//

import UIKit
import SnapKit

internal protocol HamatonBottomViewDelegate: NSObjectProtocol {
    
    /// 切换语言
    func hamatonBottomViewChangeLanguage();
}

class HamatonBottomView: UIView {
    
    internal weak var delegate: HamatonBottomViewDelegate?

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupUI()
    }
    
    func setupUI() {
        backgroundColor = .clear
        addSubview(button)
        
        button.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
            make.right.equalToSuperview()
            make.left.equalToSuperview()
            make.height.equalTo(30)
        }
    }
    
    lazy var button: UIButton = {
        let button = UIButton(type: .custom)
        button.backgroundColor = .clear
        if HamatonLanguageManager.shared.language != .English {
            button.setTitle(NSLocalizedString("中文", tableName: "HamatonLocalizable", comment: ""), for: .normal)
        } else {
            button.setTitle(NSLocalizedString("英文", tableName: "HamatonLocalizable", comment: ""), for: .normal)
        }
        button.setTitleColor(UIColor(hex6: 0x404040, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(14)
        button.addTarget(self, action: #selector(onClickButton), for: .touchUpInside)
        return button
    }()

    @objc func onClickButton() {
        print("hamatonBottomViewChangeLanguage")
        delegate?.hamatonBottomViewChangeLanguage()
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    
}
